<?php
/*///////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*///////////////// Additional Child Functions Start                                                               */
/*///////////////////////////////////////////////////////////////////////////////////////////////////////*/


#add javascript files to head
add_action('wp_head', 'js_in_head');

function js_in_head(){
	if(is_home()){
		?>
		<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri(); ?>/custom.js"></script>
		<?php 
	}
}

function kb_format_link_list($array = null){
	$output = "";
	$kb = 1;
	foreach ($array as $item): 
  	$output .= '<a href="'.$item->link.'">'.$item->name.'</a>';
		if($kb <> count($array)){
			$output .= ', ';
		}
		$kb++;
	endforeach;
	return $output;
}

function kb_pluralize($input = null){
	$output = '';
	$output = $input.'s';
	return $output;
}


/**
 * Adds Project_Categories widget.
 */
class Project_Categories extends WP_Widget {

	/**
	 * Register widget with WordPress.
	 */
	public function __construct() {
		parent::__construct(
	 		'project_categories', // Base ID
			'Project Categories', // Name
			array( 'description' => __( 'Displays Project Categories', 'text_domain' ), ) // Args
		);
	}

	/**
	 * Front-end display of widget.
	 *
	 * @see WP_Widget::widget()
	 *
	 * @param array $args     Widget arguments.
	 * @param array $instance Saved values from database.
	 */
	public function widget( $args, $instance ) {
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );

		echo $before_widget;
		if ( ! empty( $title ) ){
			echo $before_title . $title . $after_title;
		}else{
			echo '<h3 class="widget-title">Project Categories</h3>';
		}
			echo '<ul>';
			simple_portfolio_list_categories();
			echo '</ul>';
		echo $after_widget;
	}

	/**
	 * Sanitize widget form values as they are saved.
	 *
	 * @see WP_Widget::update()
	 *
	 * @param array $new_instance Values just sent to be saved.
	 * @param array $old_instance Previously saved values from database.
	 *
	 * @return array Updated safe values to be saved.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = array();
		$instance['title'] = strip_tags( $new_instance['title'] );

		return $instance;
	}

	/**
	 * Back-end widget form.
	 *
	 * @see WP_Widget::form()
	 *
	 * @param array $instance Previously saved values from database.
	 */
	public function form( $instance ) {
		if ( isset( $instance[ 'title' ] ) ) {
			$title = $instance[ 'title' ];
		}
		else {
			$title = __( '', 'text_domain' );
		}
		?>
		<p>
		<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
		<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
		</p>
		<?php 
	}

} // class Project_Categories

// register Project_Categories widget
add_action( 'widgets_init', create_function( '', 'register_widget( "project_categories" );' ) );
   
	 
/**
 * Adds Project_Tags widget.
 */
class Project_Tags extends WP_Widget {

	/**
	 * Register widget with WordPress.
	 */
	public function __construct() {
		parent::__construct(
	 		'project_tags', // Base ID
			'Project Tags', // Name
			array( 'description' => __( 'Displays Project Tags', 'text_domain' ), ) // Args
		);
	}

	/**
	 * Front-end display of widget.
	 *
	 * @see WP_Widget::widget()
	 *
	 * @param array $args     Widget arguments.
	 * @param array $instance Saved values from database.
	 */
	public function widget( $args, $instance ) {
		extract( $args );
		$title = apply_filters( 'widget_title', $instance['title'] );

		echo $before_widget;
		if ( ! empty( $title ) ){
			echo $before_title . $title . $after_title;
		}else{
			echo '<h3 class="widget-title">Project Tags</h3>';
		}
			echo '<ul>';
			simple_portfolio_list_tags();
			echo '</ul>';
		echo $after_widget;
	}

	/**
	 * Sanitize widget form values as they are saved.
	 *
	 * @see WP_Widget::update()
	 *
	 * @param array $new_instance Values just sent to be saved.
	 * @param array $old_instance Previously saved values from database.
	 *
	 * @return array Updated safe values to be saved.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = array();
		$instance['title'] = strip_tags( $new_instance['title'] );

		return $instance;
	}

	/**
	 * Back-end widget form.
	 *
	 * @see WP_Widget::form()
	 *
	 * @param array $instance Previously saved values from database.
	 */
	public function form( $instance ) {
		if ( isset( $instance[ 'title' ] ) ) {
			$title = $instance[ 'title' ];
		}
		else {
			$title = __( '', 'text_domain' );
		}
		?>
		<p>
		<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
		<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
		</p>
		<?php 
	}

} // class Project_Tags

// register Project_Tags widget
add_action( 'widgets_init', create_function( '', 'register_widget( "project_tags" );' ) );
	   
/*///////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*///////////////// Additional Child Functions End                                                                 */
/*///////////////////////////////////////////////////////////////////////////////////////////////////////*/
?>